package com.blockchain.nodes.web.controller.manager;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.blockchain.nodes.common.annotation.Log;
import com.blockchain.nodes.common.enums.BusinessType;
import com.blockchain.nodes.manager.domain.NodesConfig;
import com.blockchain.nodes.manager.service.INodesConfigService;
import com.blockchain.nodes.framework.web.base.BaseController;
import com.blockchain.nodes.common.page.TableDataInfo;
import com.blockchain.nodes.common.base.AjaxResult;
import com.blockchain.nodes.common.utils.poi.ExcelUtil;

/**
 * 节点配置 信息操作处理
 * 
 * @author Gene Max
 * @date 2019-03-08
 */
@Controller
@RequestMapping("/manager/nodesConfig")
public class NodesConfigController extends BaseController
{
    private String prefix = "manager/nodesConfig";
	
	@Autowired
	private INodesConfigService nodesConfigService;
	
	@RequiresPermissions("manager:nodesConfig:view")
	@GetMapping()
	public String nodesConfig()
	{
	    return prefix + "/nodesConfig";
	}
	
	/**
	 * 查询节点配置列表
	 */
	@RequiresPermissions("manager:nodesConfig:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(NodesConfig nodesConfig)
	{
		startPage();
        List<NodesConfig> list = nodesConfigService.selectNodesConfigList(nodesConfig);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出节点配置列表
	 */
	@RequiresPermissions("manager:nodesConfig:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(NodesConfig nodesConfig)
    {
    	List<NodesConfig> list = nodesConfigService.selectNodesConfigList(nodesConfig);
        ExcelUtil<NodesConfig> util = new ExcelUtil<NodesConfig>(NodesConfig.class);
        return util.exportExcel(list, "nodesConfig");
    }
	
	/**
	 * 新增节点配置
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存节点配置
	 */
	@RequiresPermissions("manager:nodesConfig:add")
	@Log(title = "节点配置", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(NodesConfig nodesConfig)
	{		
		return toAjax(nodesConfigService.insertNodesConfig(nodesConfig));
	}

	/**
	 * 修改节点配置
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		NodesConfig nodesConfig = nodesConfigService.selectNodesConfigById(id);
		mmap.put("nodesConfig", nodesConfig);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存节点配置
	 */
	@RequiresPermissions("manager:nodesConfig:edit")
	@Log(title = "节点配置", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(NodesConfig nodesConfig)
	{		
		return toAjax(nodesConfigService.updateNodesConfig(nodesConfig));
	}
	
	/**
	 * 删除节点配置
	 */
	@RequiresPermissions("manager:nodesConfig:remove")
	@Log(title = "节点配置", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(nodesConfigService.deleteNodesConfigByIds(ids));
	}
	
}
